var http=new XMLHttpRequest();
window.onload=()=>{
    const searchParams = new URLSearchParams(location.search);
    const code= searchParams.get("code");
    const state= searchParams.get("state");
    
    //const redirect_uri="https://developer.kdocs.cn/h5/auth?scope=user_basic,edit_personal_files&redirect_uri=https://fxzqf.gitee.io/&state=state&app_id=AK20220921TSPWLO&state=";  
    const redirect_uri="https://openapi.wps.cn/oauthapi/v2/authorize?response_type=code&appid=AK20220802GXRKQQ&autologin=false&redirect_uri=https://fxzqf.gitee.io&scope=user_info&state=STATE";  
    const lastCode=sessionStorage.getItem("lastCode");

    if(code) {
        
        if(code==lastCode) 
            window.location.href= redirect_uri;
        else
            sessionStorage.setItem("lastCode",code);
    }
    else
    {
        window.location.href= redirect_uri;
    }
    http.open("GET", "https://openapi.wps.cn/oauthapi/v2/token?appid=AK20220802GXRKQQ&appkey=a2877119d57abd5e069aabf4249c5dd5&code=" + code, false);
    http.send();
    var access_token=JSON.parse(http.responseText).token.access_token;
    console.log(access_token);
    http.open("GET","https://openapi.wps.cn/oauthapi/v3/app/files/list?access_token="+access_token+"&appid=AK20220802GXRKQQ&open_parentid=0");
    http.setRequestHeader("Content-Type","application/json");
    http.send();
    console.log(http.responseText);
    //var access_token=JSON.parse(http.responseText).token.access_token;
    //console.log(access_token);
}



        
        //
        //
        //http.setRequestHeader("Access-Control-Allow-Origin","https://fxzqf.gitee.io")
        //http.send();
